import { createRouter, createWebHistory } from 'vue-router'
import beforeEachHandler from './permission'
import routesGames from './routes/games'
import routesDevice from './routes/device'
import routesVersion from './routes/version'
import routesMaterial from './routes/material'
import routesUsers from './routes/users'
import routesLog from './routes/log'
import { useUserStore } from '@/stores'

const router = createRouter({
  history: createWebHistory(import.meta.env.BASE_URL),
  routes: [
    {
      path: '/',
      redirect: () => (useUserStore().isLogined ? '/user/list' : '/login')
    },
    {
      path: '/login',
      name: 'login',
      component: () => import('@/views/login.vue')
    },
    // {
    //   path: '/sign-in',
    //   name: 'sign-in',
    //   component: () => import('@/views/sign-in.vue')
    // },
    // {
    //   path: '/forget-password',
    //   name: 'forget-password',
    //   component: () => import('@/views/forget-password.vue')
    // },

    // 赛事
    routesGames,
    // 设备
    routesDevice,
    // 版本
    routesVersion,
    // 用户
    routesUsers,
    // 素材
    routesMaterial,
    // 日志
    routesLog
  ]
})

// 注册全局前置守卫
router.beforeEach(beforeEachHandler)

export default router
